﻿Type.registerNamespace('RibbonCustomization');
var _samplePageComponent;

RibbonCustomization.SamplePageComponent = function () {
    RibbonCustomization.SamplePageComponent.initializeBase(this);
}

RibbonCustomization.SamplePageComponent.init = function () {
    if (_samplePageComponent == null || _samplePageComponent == 'undefined') {
        _samplePageComponent = new RibbonCustomization.SamplePageComponent();
        SP.Ribbon.PageManager.get_instance().addPageComponent(_samplePageComponent);
    }
    return _samplePageComponent;
}

RibbonCustomization.SamplePageComponent.prototype =
{
    toggleState: false,

    init: function () {
    },

    isFocusable: function () {
        return true;
    },

    receiveFocus: function () {
        return true;
    },

    yieldFocus: function () {
        return true;
    },

    getFocusedCommands: function () {
        return new Array();
    },

    getGlobalCommands: function () {
        var commands = new Array();
        Array.add(commands, 'Ribbon.TabWithToggleButton');
        Array.add(commands, 'Ribbon.TabWithToggleButton.DemoGroup');
        Array.add(commands, 'Ribbon.TabWithToggleButton.DemoGroup.ClientSideToggleButton');
        Array.add(commands, 'Ribbon.TabWithToggleButton.DemoGroup.ClientSideToggleButtonQuery');
        Array.add(commands, 'Ribbon.TabWithToggleButton.DemoGroup.ServerSideToggleButton');
        Array.add(commands, 'Ribbon.TabWithToggleButton.DemoGroup.ServerSideToggleButtonQuery');
        return commands;
    },

    canHandleCommand: function (commandId) {
        if (commandId == 'Ribbon.TabWithToggleButton' ||
            commandId == 'Ribbon.TabWithToggleButton.DemoGroup' ||
            commandId == 'Ribbon.TabWithToggleButton.DemoGroup.ClientSideToggleButton' ||
            commandId == 'Ribbon.TabWithToggleButton.DemoGroup.ClientSideToggleButtonQuery' ||
            commandId == 'Ribbon.TabWithToggleButton.DemoGroup.ServerSideToggleButton' ||
            commandId == 'Ribbon.TabWithToggleButton.DemoGroup.ServerSideToggleButtonQuery') {
            return true;
        }
        return false;
    },

    handleCommand: function (commandId, properties, sequence) {
        if (commandId == 'Ribbon.TabWithToggleButton.DemoGroup.ClientSideToggleButton') {
            this.toggleState = !this.toggleState;
        }
        else if (commandId == 'Ribbon.TabWithToggleButton.DemoGroup.ClientSideToggleButtonQuery') {
            properties.On = this.toggleState;
        }
        else {
            HandleSamplePageComponentWithPostbackCommand(commandId, properties, sequence);
        }
        return true;
    }
}

RibbonCustomization.SamplePageComponent.registerClass('RibbonCustomization.SamplePageComponent', SP.Ribbon.WebPartComponent);
if (typeof (Sys) != "undefined" && Sys && Sys.Application) {
    Sys.Application.notifyScriptLoaded();
}
NotifyScriptLoadedAndExecuteWaitingJobs("SamplePageComponentWithQuery.js");